﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using BugTracker.WebUX.WebCode;
using BugTracker.Core.Infrastructure.Exceptions;

namespace BugTracker.WebUX
{
    public class Global : System.Web.HttpApplication
    {
        private static IoCBootstrap iocBoot = null;

        public static IoCBootstrap IoC
        {
            get
            {
                return iocBoot;
            }
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            iocBoot = new IoCBootstrap();
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();
            if (ex as System.Threading.ThreadAbortException != null && ex as BTDataAccessException != null)
            {
                //Do not handle any ThreadAbortException or BLLException here
                //Only handle other custom exception (DALException in this example)
                //and any other unhandled Exceptions here
                BTLogger.HandleError(ex);
                Response.Redirect(string.Format("Error.aspx?aspxerrorpath={0}",  Request.Url.PathAndQuery));
            }
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}